Public Class RailPoint
    ' Index de la station de départ de l'aiguillage
    Private _StartStationIndex As Integer
    Public Property StartStationIndex() As Integer
        Get
            Return _StartStationIndex
        End Get
        Set(ByVal Value As Integer)
            _StartStationIndex = Value
        End Set
    End Property

    ' Index de la station au milieu de l'aiguillage (créée)
    Private _MiddleStationIndex As Integer
    Public Property MiddleStationIndex() As Integer
        Get
            Return _MiddleStationIndex
        End Get
        Set(ByVal Value As Integer)
            _MiddleStationIndex = Value
        End Set
    End Property

    ' Index de la première station d'arrivé de l'aiguillage
    Private _EndStation1Index As Integer
    Public Property EndStation1Index() As Integer
        Get
            Return _EndStation1Index
        End Get
        Set(ByVal Value As Integer)
            _EndStation1Index = Value
        End Set
    End Property

    ' Index de la deuxième station d'arrivé de l'aiguillage
    Private _EndStation2Index As Integer
    Public Property EndStation2Index() As Integer
        Get
            Return _EndStation2Index
        End Get
        Set(ByVal Value As Integer)
            _EndStation2Index = Value
        End Set
    End Property

    ' Jonction active : vrai si MILIEU vers END1, faux si MILIEU vers END2
    Private _ActiveJunction As Boolean
    Public Property ActiveJunction() As Boolean
        Get
            Return _ActiveJunction
        End Get
        Set(ByVal Value As Boolean)
            _ActiveJunction = Value
        End Set
    End Property

    ' Points composant les lignes de l'aiguillage afin d'effacer le centre de l'aiguillage
    Private P1, P2, P3, P4, P5, P6 As Point

    ' Constructeur sans connaître la jonction active (par défaut MILIEU vers END1)
    Sub New(ByVal StartStationIndex As Integer, ByVal MiddleStationIndex As Integer, _
            ByVal EndStation1Index As Integer, ByVal EndStation2Index As Integer)
        _StartStationIndex = StartStationIndex
        _MiddleStationIndex = MiddleStationIndex
        _EndStation1Index = EndStation1Index
        _EndStation2Index = EndStation2Index
        _ActiveJunction = True
    End Sub

    ' Constructeur en connaissant la jonction active
    Sub New(ByVal StartStationIndex As Integer, ByVal MiddleStationIndex As Integer, _
            ByVal EndStation1Index As Integer, ByVal EndStation2Index As Integer, ByVal ActiveJunction As Boolean)
        _StartStationIndex = StartStationIndex
        _MiddleStationIndex = MiddleStationIndex
        _EndStation1Index = EndStation1Index
        _EndStation2Index = EndStation2Index
        _ActiveJunction = ActiveJunction
    End Sub

    ' Calcul des coordonnées des points de l'aiguillage
    Public Sub CalculateCoords(ByRef Stations As Dictionary(Of Integer, Station))
        ' Angle entre la station du milieu et la station de départ
        Dim A1 As Double = GetAngle(Stations.Item(_MiddleStationIndex), Stations.Item(_StartStationIndex))

        ' Calcul des points
        P1 = New Point(Stations.Item(_MiddleStationIndex).X + Math.Cos(A1 - Math.PI / 4) * 7, _
                       Stations.Item(_MiddleStationIndex).Y + Math.Sin(A1 - Math.PI / 4) * 7)

        P2 = New Point(Stations.Item(_MiddleStationIndex).X + Math.Cos(A1 + Math.PI / 4) * 7, _
                       Stations.Item(_MiddleStationIndex).Y + Math.Sin(A1 + Math.PI / 4) * 7)

        ' Angle entre la station du milieu et la première station de fin
        Dim A2 As Double = GetAngle(Stations.Item(_MiddleStationIndex), Stations.Item(_EndStation1Index))

        P3 = New Point(Stations.Item(_MiddleStationIndex).X + Math.Cos(A2 - Math.PI / 4) * 7, _
                       Stations.Item(_MiddleStationIndex).Y + Math.Sin(A2 - Math.PI / 4) * 7)

        P4 = New Point(Stations.Item(_MiddleStationIndex).X + Math.Cos(A2 + Math.PI / 4) * 7, _
                       Stations.Item(_MiddleStationIndex).Y + Math.Sin(A2 + Math.PI / 4) * 7)

        ' Angle entre la station du milieu et la deuxième station de fin
        Dim A3 As Double = GetAngle(Stations.Item(_MiddleStationIndex), Stations.Item(_EndStation2Index))

        P5 = New Point(Stations.Item(_MiddleStationIndex).X + Math.Cos(A3 - Math.PI / 4) * 7, _
                       Stations.Item(_MiddleStationIndex).Y + Math.Sin(A3 - Math.PI / 4) * 7)

        P6 = New Point(Stations.Item(_MiddleStationIndex).X + Math.Cos(A3 + Math.PI / 4) * 7, _
                       Stations.Item(_MiddleStationIndex).Y + Math.Sin(A3 + Math.PI / 4) * 7)
    End Sub

    ' Retourne le polygone formé par les points de l'aiguillage
    Public Function GetPolygon() As Point()
        Return {P1, P2, P3, P4, P5, P6}
    End Function
End Class
